// import {stCard} from "@/api/room";

function dice(diceStr,username,rid,uid){
    let message = {
        type: 'dice input',
        username: '骰娘',
        createTime: null,
        message: null
    }
    let regAttributeTest = /\.ra\s?\D+/ig
    if (regAttributeTest.test(diceStr)){
        return "dd"
    }
    let regSingleDice = /\.rd\s?\d+/ig
    if (regSingleDice.test(diceStr)){
        let reg = /\d+/ig
        let num = reg.exec(diceStr)[0]
        let result =Math.floor(Math.random() * num)+1
        message.message= username+"掷骰：1d"+num+"="+result
        return message;
    }
    let regMultiDice = /\.r\s?[\d+d\d+\+]+/ig
    if (regMultiDice.test(diceStr)){
        let reg = /\d+d\d+/ig
        let arr = diceStr.match(reg)
        let msg = username+'掷骰：'
        let diceMsg = ''
        let resultMsg = ''
        let result = 0
        for (let i = 0; i < arr.length; i++){
            let str = arr[i]
            let d = str.split("d")[0]
            let num = str.split("d")[1]
            diceMsg += d+'d'+num+'+'
            resultMsg += '('
            for (let j = 0; j < d; j++){
                let r =Math.floor(Math.random() * num)+1
                resultMsg += r+'+'
                result += r
            }
            resultMsg = resultMsg.substring(0,resultMsg.length-1)
            resultMsg += ')+'
        }
        resultMsg = resultMsg.substring(0,resultMsg.length-1)
        diceMsg = diceMsg.substring(0,diceMsg.length-1)
        msg += diceMsg+'='
        msg += resultMsg
        msg += '='+result
        message.message = msg
        return message
    }
    let regCoc = /\.coc\s?\d*/ig
    if (regCoc.test(diceStr)){
        let reg = /\d+/ig
        let times = 1
        if (reg.exec(diceStr) != null){
            console.log(reg.exec(diceStr))
            times = reg.exec(diceStr)[0]
        }
        let arr = ['力量','体质','体型','敏捷','外貌','智力','意志','教育']
        let msg = "[COC7]人物卡作成:\n"
        for (let i = 0; i < times; i++){
            let total = 0
            let tmpMsg = ""
            for (let j = 0; j < arr.length; j++){
                let t1 = Math.floor(Math.random() * 6)+1
                let t2 = Math.floor(Math.random() * 6)+1
                let t3 = Math.floor(Math.random() * 6)+1
                let t = (t1+t2+t3)*5
                tmpMsg += arr[i]+":"+t+" "
                total += t
            }
            let t1 = Math.floor(Math.random() * 6)+1
            let t2 = Math.floor(Math.random() * 6)+1
            let t3 = Math.floor(Math.random() * 6)+1
            let t = (t1+t2+t3)*5
            tmpMsg += "幸运:"+t+" 共计"+total+'/'+(total+t)+" "+(total/(total+t)).toFixed(4)*100+"%\n"
            msg += tmpMsg
        }
        msg = msg.substring(0,msg.length-1)
        message.message = msg
        return message
    }
    let regSt = /\.st .+/ig
    if (regSt.test(diceStr)){
        diceStr = diceStr.replace(".st ","")
        let reg = /\D+\d+/ig
        let arr = diceStr.match(reg)
        let responseEntry = {}
        for (let i = 0; i < arr.length; i++){
            let str = arr[i]
            let reg1 = /\D+/ig
            let reg2 = /\d+/ig
            let key = reg1.exec(str)[0]
            let value = reg2.exec(str)[0]
            responseEntry[key] = value
        }
        let attributeStr = JSON.stringify(responseEntry)
        return attributeStr
    }
    return "未知指令，无法处理"
}

console.log(dice(".st 力量80",))
//.st 力量50str50敏捷85dex85意志70pow70体质50con50外貌35app35教育80edu80体型85siz85智力65灵感65int65san70san值70理智70理智值70幸运50运气50mp14魔法14hp13体力13会计5人类学1估价5考古学51魅惑15攀爬60计算机5计算机使用5电脑5信用30信誉30信用评级30克苏鲁0克苏鲁神话0cm0乔装5闪避42汽车20驾驶20汽车驾驶20电气维修10电子学1话术5斗殴75绞具15手枪20喷射器10急救30历史55恐吓15跳跃20中文41母语80法律5图书馆60图书馆使用60聆听20开锁1撬锁1锁匠1机械维修10医学1博物学50自然学50领航10导航10神秘学5重型操作1重型机械1操作重型机械1重型1说服60精神分析1心理学10骑术5地质学21妙手10侦查65潜行20生存10游泳20投掷20追踪10驯兽5潜水1爆破1读唇1催眠1炮术1

// let reg = /\s\D+/
// let str = reg.exec(".ra 起飞")[0]
// console.log(str.replaceAll(" ",""))